package ch.bfh.swos.learnaid.service;


import javax.inject.Inject;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import ch.bfh.swos.learnaid.service.dto.QuestionDTO;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/serviceContext.xml")
public class QuestionServiceIT {

	@Inject
	private QuestionService questionService;

	@Test
	public void test() {

		// Create
	    QuestionDTO newQuestion = new QuestionDTO();
		newQuestion.setText("Test");
		newQuestion = questionService.create(newQuestion);

		// Read
		QuestionDTO readQuestion = questionService.read(newQuestion.getId());
		Assert.assertTrue(newQuestion.getText().equals(readQuestion.getText()));

		// Update
		readQuestion.setText("Test2");
		readQuestion = questionService.update(readQuestion);
		QuestionDTO updatedQuestion = questionService.read(readQuestion.getId());
		Assert.assertTrue(readQuestion.getText().equals(updatedQuestion.getText()));

		// Delete
		questionService.delete(updatedQuestion);
		QuestionDTO deletedQuestion = questionService.read(readQuestion.getId());
		Assert.assertNull(deletedQuestion);
	}

}
